package com.dao.impl;

import com.dao.BaseDao;
import com.entity.House;
import com.entity.User;
import com.util.Main;
import org.hibernate.Query;
import org.hibernate.Session;
import org.junit.Test;

import java.util.List;

/**
 * Created by Administrator on 2015/7/22.
 */
public class BaseDaoImpl implements BaseDao {
    static Session session = Main.getSession();


    public User login(String userName, String passWord) {
        String hql = "from User where userName=:userName and userPassword=:userPassword";
        Query query = session.createQuery(hql);
        query.setParameter("userName", userName);
        query.setParameter("userPassword", passWord);
        List<User> userList = query.list();
        if (userList.size() == 0) {
            return null;
        } else {
            return userList.get(0);
        }
    }

    public List<House> getAllHouse() {
        String hql = "from House";
        Query query = session.createQuery(hql);
        List<House> houses = query.list();
        return houses;
    }

    @Test
    public void test() {
        System.out.println(getAllHouse());
        User user = (User) session.get(User.class, 2);
    }

}
